// src/api/football.js
import axios from 'axios'

const apiClient = axios.create({
    baseURL: '/football-api',
    headers: {
        'X-Auth-Token': 'ac73d8fd18b94d95ba13b43e4aa12c6d' // 替换真实key
    }
})

export default {
    async getTeams(competitionCode) {
        try {
            const response = await apiClient.get(`/competitions/${competitionCode}/teams`)
            return response.data.teams.map(team => ({
                id: team.id,
                name: team.shortName || team.name,
                logo: this.processCrestUrl(team.crest),
                founded: team.founded
            }))
        } catch (error) {
            console.error('API Error:', error.response?.data || error.message)
            throw error
        }
    },

    // 处理图片URL格式
    processCrestUrl(url) {
        return url?.replace(/^http:/, 'https:') || '/default_crest.svg'
    }
}